# Maintainer: Levente Polyak <anthraxx[at]archlinux[dot]org>
# Contributor: Chris Andrews <christophersimonandrews [at] gmail [dot] com>
# Contributor: FadeMind <fademind@gmail.com>
# Contributor: Serge Victor <arch@random.re>
# Contributor: Krzysztof Wloch <wloszekk [at] gmail [dot] com>
# Contributor: Luke McCarthy <luke@iogopro.co.uk>

pkgname=fasm
pkgver=1.73.30
pkgrel=1
pkgdesc='Fast and efficient self-assembling x86 assembler for DOS, Windows and Linux operating systems'
url='https://flatassembler.net/'
arch=('loong64' 'x86_64')
license=('custom')
depends_x86_64=('lib32-glibc' 'lib32-gcc-libs')
source=(https://flatassembler.net/${pkgname}-${pkgver}.tgz)
sha512sums=('1f2fa2099be41c6d30acde5361293a67b31a2f8e63f5a9bfb2b0becc53cb519340e6382c9a0d13da9a898912a8f556a53b372c74e208314c0a72ed3bec97c41a')
b2sums=('6364e455cb487a81cabe66ad4f747ae4d2773ff8d4dbc9ef118a6426eefb043e635611cea58b1e727822f905c3140a63b4d06d60f92d363ce7e06c9e6fb9f76b')

build() {
  cd ${pkgname}

  if [ "${CARCH}" == "x86_64" ]; then
    SRCDIR=Linux/x64
    ./fasm.x64 source/${SRCDIR}/fasm.asm
  fi
  mv source/${SRCDIR}/fasm ./fasm

  # tools
  local s
  for s in listing prepsrc symbols; do
    ./fasm tools/libc/${s}.asm ${s}.o
    gcc -m32 ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} -o ${s} ${s}.o
  done
}

package() {
  cd ${pkgname}

  install -Dm 755 fasm -t "${pkgdir}/usr/bin"
  # tools
  local s
  for s in listing prepsrc symbols; do
    install -Dm 755 ${s} "${pkgdir}/usr/bin/fasm-${s}"
  done

  # docs
  install -Dm 644 ${pkgname}.txt whatsnew.txt -t "${pkgdir}/usr/share/doc/${pkgname}"
  install -Dm 644 examples/elfexe/*.asm -t "${pkgdir}/usr/share/doc/${pkgname}/examples/elfexe"
  install -Dm 644 examples/elfexe/dynamic/*.asm -t "${pkgdir}/usr/share/doc/${pkgname}/examples/elfexe/dynamic"
  install -Dm 644 examples/elfexe/dynamic/*.inc -t "${pkgdir}/usr/share/doc/${pkgname}/examples/elfexe/dynamic"
  install -Dm 644 examples/elfobj/*.asm -t "${pkgdir}/usr/share/doc/${pkgname}/examples/elfobj"
  install -Dm 644 examples/libcdemo/*.asm -t "${pkgdir}/usr/share/doc/${pkgname}/examples/libcdemo"
  install -Dm 644 examples/libcdemo/*.inc -t "${pkgdir}/usr/share/doc/${pkgname}/examples/libcdemo"
  install -Dm 644 license.txt "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}

# vim: ts=2 sw=2 et:
